

import React, { FC , useState } from 'react'
import { PullToRefresh, List ,InfiniteScroll } from 'antd-mobile'
import { sleep } from 'antd-mobile/es/utils/sleep'
import ListItem from './ListItem'
import { ShowToast } from '@/utils/message'
const LoadMore:FC<any> = ({
    refreshData,   // 刷新接口
    loadDataByPage, // 加载更多接口 
    children
}) => {
    const [hasMore, setHasMore] = useState(true)


    const  loadMore =  ()=>{
        loadDataByPage( ()=>{
            // await sleep(1000)
            // ShowToast('更多数据加载成功')
            setHasMore(true)
        }, ()=>{
            // await sleep(1000)
            ShowToast('数据见底了')
            setHasMore(false)
        })
    }


    return (
        <PullToRefresh
            onRefresh={async () => {
                refreshData()
                await sleep(1000)
                
            }}
        >   
            {children}
            <InfiniteScroll loadMore={loadMore} hasMore={hasMore} threshold={500} />
        </PullToRefresh>
  )
}

export default LoadMore